package main

import (
	"fmt"
	"time"

	"gitee.com/chen_wei_jing/kinx/ziface"
	"gitee.com/chen_wei_jing/kinx/zlog"
	"gitee.com/chen_wei_jing/kinx/znet"
)

type RegisterClientRouter struct {
	znet.BaseRouter
}

func (r *RegisterClientRouter) Handle(req ziface.IRequest) {
	fmt.Println("[消息]:", string(req.GetMessage().GetData()))
}

func main() {
	timer := time.NewTimer(5 * time.Second)
	zlog.Ins().DebugF("[INIT] libclient init")
	//kcpClient = znet.NewKcpClient("120.26.183.54", 7777)
	kcpClient := znet.NewKcpClient("127.0.0.1", 7777)
	kcpClient.StartHeartBeat(2 * time.Second)

	// routers
	kcpClient.AddRouter(1, &RegisterClientRouter{})

	connId, err := kcpClient.Connect()

	if err != nil {
		zlog.Ins().ErrorF("%v\n", err)
		return
	}

	err = kcpClient.SendMsg(connId, 1, []byte("Client register test msg!"))
	if err != nil {
		zlog.Ins().ErrorF("send msg err:%v\n", err)
	}

	select {
	case <-timer.C:
	}
}
